package com.hello915.googledirectionapi.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import android.util.Log;

public class JsonHelper {

	private String TAG = "gson";
	private final Gson gson = new GsonBuilder().setDateFormat(
			"yyyy-MM-dd HH:mm:ss").create();

	public Object jsonToBean(String json, Class<?> type){
		Object result = null;
		if(json != null){
			try {
				result = gson.fromJson(json, type);
			}catch(Exception e){
				Log.e(TAG,e.getMessage()+"");
			}
		}
		return result;
	}
	
	public String toJsonString(Object o){
		String jsonStr = gson.toJson(o);
		Log.i(TAG, "Obj2JSON:" + jsonStr);
		return jsonStr;
	}
}
